package com.tansty.security.config.swagger;

/**
 * description: Swagger的配置 <br>
 * date: 2021/8/1 16:53 <br>
 * author: ztz <br>
 * version: 1.0 <br>
 */

import com.google.common.base.Predicate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
/**
 * description:  <br>
 * date: 2021/7/21 14:45 <br>
 * author: ztz <br>
 * version: 1.0 <br>
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket docket(Environment environment){
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                // 查看当前所处的环境是否是指定的环境，是就可以访问swaggerui.html页面
                .enable(environment.acceptsProfiles(Profiles.of("dev", "test")))
                .groupName("tansty")
                .select()
                // 扫描指定的包的接口
                .apis(RequestHandlerSelectors.basePackage("com.tansty.security"))
                //.paths(PathSelectors.ant("/tansty")) paths过滤指定的接口
                .build();
    }
    /**
     * @Description 文档信息描述
     * @author Tansty
     * @date 2021/7/21 15:31
     * @return springfox.documentation.service.ApiInfo
     */
    private ApiInfo apiInfo(){
        Contact contact = new Contact("Tansty", "https://blog.csdn.net/tansty_zh", "tanstyztz@qq.com");
        return new ApiInfo("Tansty的api文档", "api接口", "v-1.0", "https://blog.csdn.net/tansty_zh",
                contact, "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList<VendorExtension>());
    }
}
